package com.jackeys.piaems.vo;

import com.jackeys.piaems.util.StatusEnumUtil;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName: ResponseVo
 * @Description: 返回类
 * @Author: Jackeys
 * @Date: 2021-06-11 13:38
 * @Version: 1.0
 */
public class ResponseVo implements Serializable {
    /**
     * 状态码
     */
    private Integer code;
    /**
     * 状态信息
     */
    private String msg;
    /**
     * 数据域
     */
    private Map<String, Object> data = new HashMap<>();

    public ResponseVo() {
    }

    public ResponseVo(StatusEnumUtil statusEnumUtil) {
        this.code = statusEnumUtil.getCode();
        this.msg = statusEnumUtil.getMsg();
    }

    public ResponseVo(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResponseVo(Integer code, String msg, Map<String, Object> data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public ResponseVo add(String key, Object value) {
        this.getData().put(key, value);
        return this;
    }

    public static ResponseVo userNeedLogin(){
        return new ResponseVo(2001,"用户信息已过期，请重新登录");
    }
    public static ResponseVo loginDistance(){
        return new ResponseVo(2002,"用户异地登录");
    }
    public static ResponseVo authenticationSuccess(Object object){
        return new ResponseVo(1001,"认证成功").add("user",object);
    }
    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public void setData(Map<String, Object> data) {
        this.data = data;
    }
}
